<?php

$iAreaLen = 30;

set_time_limit(0);
$GLOBALS['stdin'] = fopen ("php://stdin","r");

echo "phame of live 0.0.0.001\n";
echo "-----------------------\n";


// zainicjuj przestrzen
$area = area::getInstance($iAreaLen);

while(true){

	$sCmd = prompt('your Cmd?');

	if($sCmd == 'exit' or $sCmd == 'e'){
		die();
	}

	$iRepeat = 1;

	if(preg_match('!^(\d+)x (.*)!', $sCmd, $shFound)){
		$iRepeat = (int)$shFound[1];
		$sCmd = $shFound[2];
	}

	for($x = 0; $x < $iRepeat; $x ++){

		if(is_numeric($sCmd)){
			item::getItemById($sCmd) -> printInfo();
		}

		if($sCmd == 'map'){
			$area -> printMap();
		}

		if($sCmd == 'new item'){
			$a = new item();
		}

		if(preg_match('!item (\d+) info!', $sCmd, $shFound)){
/*{{{*/
			// info o itemie
			item::getItemById($shFound[1]) -> printInfo();
/*}}}*/
		}

		if($sCmd == 'hb'){
/*{{{*/
			echo "tik-tak \n";
			item::tick();
/*}}}*/
		}

		if($sCmd == 't' or $sCmd == 'st'){
/*{{{*/
			item::tick();
			$area -> printMap();

			if($sCmd == 'st'){
				sleep(1);
			}
/*}}}*/
		}
	}

}





function prompt($sPrompt = '-->', $iLength = 255){
/*{{{*/
	echo "\n{$sPrompt}";
	$line = fgets ($GLOBALS['stdin'], $iLength);
	return trim ($line);
/*}}}*/
}

function __autoload($sClass){
/*{{{*/
	include 'class/' . $sClass . '/' . $sClass . '.class.php';
/*}}}*/
}

?>
